home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / dev / mui / S3DC.lha / S3DC / main.c next >
C/C++ Source or Header  |  1999-09-20  |  3KB  |  152 lines

  1. /*
  2.                   S3DC test
  3.  
  4.   This a simple demo showing how to compile MUI apps
  5.   with GCC. It just draw a cube, which can be moved
  6.                 with arrow keys.
  7.  
  8.             (C) Olivier Croquette
  9.  
  10.   For any question or comment, please write to :
  11.  
  12.             ocroquette@nordnet.fr
  13.  
  14.  
  15.  
  16. */
  17.  
  18.  
  19.  
  20. #include <stdio.h>
  21.  
  22. #include <proto/intuition.h>
  23. #include <proto/graphics.h>
  24. #include <proto/exec.h>
  25. #include <proto/muimaster.h>
  26.  
  27.  
  28. #include <libraries/mui.h>
  29.  
  30. #include "S3DC.h"
  31.  
  32. struct GfxBase *GfxBase;
  33. struct IntuitionBase *IntuitionBase;
  34. struct Library  *MUIMasterBase;
  35.  
  36.  
  37. #define MAKE_ID(a,b,c,d) ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  38.  
  39. BOOL Open_Libs(void )
  40. {
  41.   if ( !(IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",39)) )
  42.     return(0);
  43.  
  44.   if ( !(GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",0)) )
  45.   {
  46.     CloseLibrary((struct Library *)IntuitionBase);
  47.     return(0);
  48.   }
  49.  
  50.   if ( !(MUIMasterBase=OpenLibrary(MUIMASTER_NAME,19)) )
  51.   {
  52.     CloseLibrary((struct Library *)GfxBase);
  53.     CloseLibrary((struct Library *)IntuitionBase);
  54.     return(0);
  55.   }
  56.  
  57.   return(1);
  58. }
  59.  
  60. void Close_Libs(void )
  61. {
  62.   if ( IntuitionBase )
  63.     CloseLibrary((struct Library *)IntuitionBase);
  64.  
  65.   if ( GfxBase )
  66.     CloseLibrary((struct Library *)GfxBase);
  67.  
  68.   if ( MUIMasterBase )
  69.     CloseLibrary(MUIMasterBase);
  70. }
  71.  
  72.  
  73. int main(int argc,char *argv[])
  74. {
  75.   APTR app,window,MyObj;
  76.   struct MUI_CustomClass *mcc;
  77.  
  78.   if ( ! Open_Libs() )
  79.   {
  80.     printf("Cannot open libs\n");
  81.     return(0);
  82.   }
  83.  
  84.   if (!(mcc = MUI_CreateCustomClass(NULL,MUIC_Area,NULL,sizeof(struct S3DC_Data),S3DC_Dispatcher)))
  85.   {
  86.     printf("Cannot create custom class.\n");
  87.     return(0);
  88.   }
  89.  
  90.   app = ApplicationObject,
  91.     MUIA_Application_Title  , "S3DC",
  92.     MUIA_Application_Version , "$VER: S3DC 1.0 (20.09.99)",
  93.     MUIA_Application_Copyright , "©1999, Olivier Croquette",
  94.     MUIA_Application_Author  , "Olivier Croquette",
  95.     MUIA_Application_Description, "Just a useless software showing a cube.",
  96.     MUIA_Application_Base  , "S3DC",
  97.  
  98.     SubWindow, window = WindowObject,
  99.       MUIA_Window_Title, "Simple 3D Cube",
  100.       MUIA_Window_ID , MAKE_ID('S','3','D','C'),
  101.       WindowContents, VGroup,
  102.  
  103.         Child, TextObject,
  104.           TextFrame,
  105.           MUIA_Background, MUII_TextBack,
  106.           MUIA_Text_Contents, "\33cSimple 3D Cube\nby O.Croquette.\n(ocroquette@nordnet.fr)",
  107.           End,
  108.  
  109.         Child, MyObj = NewObject(mcc->mcc_Class,NULL,
  110.           TextFrame,
  111.           TAG_DONE),
  112.  
  113.         End,
  114.  
  115.       End,
  116.     End;
  117.  
  118.   if (!app)
  119.   {
  120.     printf("Cannot create application.\n");
  121.     return(0);
  122.   }
  123.  
  124.   set(window,MUIA_Window_DefaultObject, MyObj);
  125.  
  126.   DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  127.     app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  128.  
  129.  
  130.   set(window,MUIA_Window_Open,TRUE);
  131.  
  132.   {
  133.     ULONG sigs = 0;
  134.  
  135.     while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
  136.     {
  137.       if (sigs)
  138.       {
  139.         sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  140.         if (sigs & SIGBREAKF_CTRL_C) break;
  141.       }
  142.     }
  143.   }
  144.  
  145.   set(window,MUIA_Window_Open,FALSE);
  146.  
  147.  
  148.   MUI_DisposeObject(app);
  149.   MUI_DeleteCustomClass(mcc);
  150.   Close_Libs();
  151. }
  152.